package com.mantou.scucorse.core.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.mantou.scucorse.core.entity.Cookie;
import com.mantou.scucorse.core.repository.CookieRepository;
import com.mantou.scucorse.core.service.CookieService;

@Service
public class CookieService {


	@Resource
	private CookieRepository cookieRepo;

	@Transactional
	public int create(Cookie cookie) {
		 cookieRepo.insert(cookie);
		 return cookie.getId();
	}

	@Transactional
	public int createSelective(Cookie cookie) {
		 cookieRepo.insertSelective(cookie);
		 return cookie.getId();
	}

	@Transactional
	public int deleteByPrimaryKey(Integer id) {
		return cookieRepo.deleteByPrimaryKey(id);
	}

	@Transactional(readOnly = true)
	public Cookie findByPrimaryKey(Integer id) {
		Cookie cookie = cookieRepo.selectByPrimaryKey(id);
		return cookie;
	}

	@Transactional(readOnly = true)
	public int selectCount(Cookie cookie) {
		return cookieRepo.selectCount(cookie);
	}

	@Transactional
	public int updateByPrimaryKey(Cookie cookie) {
		return cookieRepo.updateByPrimaryKey(cookie);
	}
	
	@Transactional
	public int updateByPrimaryKeySelective(Cookie cookie) {
		return cookieRepo.updateByPrimaryKeySelective(cookie);
	}

	public List<Cookie> findByUserID(Integer userid) {
		// TODO Auto-generated method stub
		Cookie queryCookie = new Cookie();
		queryCookie.setUserid(userid);
		return cookieRepo.selectPage(queryCookie, new PageRequest(0,Integer.MAX_VALUE));
	}

	public Cookie find(Cookie querycookie) {
		// TODO Auto-generated method stub
		List<Cookie> cookies = cookieRepo.selectPage(querycookie, new PageRequest(0,10));
		if(cookies.size() == 0){
			return null;
		}
		return cookies.get(0);
	}

}
